package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type ConstantInfoApi struct {
}

var constantInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ConstantInfoService


// CreateConstantInfo 创建ConstantInfo
// @Tags ConstantInfo
// @Summary 创建ConstantInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ConstantInfo true "创建ConstantInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /constantInfo/createConstantInfo [post]
func (constantInfoApi *ConstantInfoApi) CreateConstantInfo(c *gin.Context) {
	var constantInfo autocode.ConstantInfo
	_ = c.ShouldBindJSON(&constantInfo)
	if err := constantInfoService.CreateConstantInfo(constantInfo); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteConstantInfo 删除ConstantInfo
// @Tags ConstantInfo
// @Summary 删除ConstantInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ConstantInfo true "删除ConstantInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /constantInfo/deleteConstantInfo [delete]
func (constantInfoApi *ConstantInfoApi) DeleteConstantInfo(c *gin.Context) {
	var constantInfo autocode.ConstantInfo
	_ = c.ShouldBindJSON(&constantInfo)
	if err := constantInfoService.DeleteConstantInfo(constantInfo); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteConstantInfoByIds 批量删除ConstantInfo
// @Tags ConstantInfo
// @Summary 批量删除ConstantInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ConstantInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /constantInfo/deleteConstantInfoByIds [delete]
func (constantInfoApi *ConstantInfoApi) DeleteConstantInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := constantInfoService.DeleteConstantInfoByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateConstantInfo 更新ConstantInfo
// @Tags ConstantInfo
// @Summary 更新ConstantInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ConstantInfo true "更新ConstantInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /constantInfo/updateConstantInfo [put]
func (constantInfoApi *ConstantInfoApi) UpdateConstantInfo(c *gin.Context) {
	var constantInfo autocode.ConstantInfo
	_ = c.ShouldBindJSON(&constantInfo)
	if err := constantInfoService.UpdateConstantInfo(constantInfo); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindConstantInfo 用id查询ConstantInfo
// @Tags ConstantInfo
// @Summary 用id查询ConstantInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.ConstantInfo true "用id查询ConstantInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /constantInfo/findConstantInfo [get]
func (constantInfoApi *ConstantInfoApi) FindConstantInfo(c *gin.Context) {
	var constantInfo autocode.ConstantInfo
	_ = c.ShouldBindQuery(&constantInfo)
	if err, reconstantInfo := constantInfoService.GetConstantInfo(constantInfo.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reconstantInfo": reconstantInfo}, c)
	}
}

// GetConstantInfoList 分页获取ConstantInfo列表
// @Tags ConstantInfo
// @Summary 分页获取ConstantInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.ConstantInfoSearch true "分页获取ConstantInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /constantInfo/getConstantInfoList [get]
func (constantInfoApi *ConstantInfoApi) GetConstantInfoList(c *gin.Context) {
	var pageInfo autocodeReq.ConstantInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := constantInfoService.GetConstantInfoInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
